<% %>
<div id="print" style="font-size:12px;text-align:right;width:100%">
<a href="javascript:window.print();"><%=image_tag"printer.gif",:border=>0,:alt=>'To preview the print result, use File-> Print Preview'.t%><%='Print'.t%></a>
</div>
<table class="TimeTrack">
 <tr>
     <td><%='Report Time Zone'.t%>:</td>
     <td colspan=3>
     <%=@start_at%> - <%=@end_at%>
     </td>
 </tr>
 <tr>
     <td><%='Selected Projects'.t%>:</td>
     <td style="white-space:normal" colspan=3>
       <%@projects.each do |project|%>
	     <%=link_to project.name,:controller=>'project',:action=>'show',:id=>project.id%>
       <%end%>
     </td>
 </tr>
 <tr>
   <td><%='Confirm Type'.t%>:</td>
	<td colspan=3><%=@confirmed_time.t%></td>
 </tr>
 <tr>
   <td><%='Work Type'.t%>:</td>
	<td colspan=3><%=@work_time.t%></td>
 </tr>
 <tr>
   <th align=left><%='Project name'.t%>:</th>
   <th align=left><span style="width:120px"><%='Username'.t%></span><%='Hours'.t%> / [<%="hours".t%>:<%='Activity Types'.t%>]
   </th>
   <th align=right>
                  <%='User/Project Time Rate'.t%>
   </th>
   <th align=left><%='Total'.t%></th>
 </tr>
 <%
  p_count = 0
  p_total = 0
 %>
 <%@projects.each do |project|%>
 <%pt = project.total_hours(@start_at,@end_at,@confirmed_time,@work_time)%> 

 <tr>
   <td valign=top width=20%>
      <%=link_to project.name,:controller=>"project",:action=>'show',:id=>project.id%>
   </td>
   <td width=60% valign=top colspan=2> 
     <table style="border-collapse:collapse" width=100%>
     <%project.users.each do |u|%>
	   <%ut = uanyt = project.hours(u.id,@start_at,@end_at,@confirmed_time,@work_time)%>
	   <tr>
	     <td valign=top><%=link_to u.name,:controller=>'user',:action=>'show',:id=>u.id%></td>
		 <td>
         <!-- user activity type time detail -->
		 <%if ut > 0%>
		  <table style="border-collapse:collapse">
	      <%project.activity_types.each do |a|%>
		    <%uat = project.hours(u.id,a.id,@start_at,@end_at,@confirmed_time,@work_time)%>
			 <%if uat >0%>
             <tr><td><%=a.name%></td><td> <%=sprintf('%0.2f',(uat))%></td></tr>
		       <%uanyt = uanyt - uat%>
			 <%end%>
		   <%end%> 
		   <%if uanyt > 0%>
            <tr><td><%='ANY type'.t%></td><td><%=sprintf('%0.2f',uanyt)%></td></tr>
		   <%end%>
		   </table>
		 <%end%>
		  </td>
		  <td valign=top align=right style="padding:2px;">
		   <%=pt == 0 ? 0.00 : sprintf('%0.2f',ut*100/pt)%>%
	        <span style="width:102px;padding:0px;text-align:left;margin-right:0px;height:8px;background:#ccc;border:1px #666 solid;">
		     <span style="width:<%=pt == 0 ? 0 : ut*100/pt%>px;background:#666"> </span>
		    </span>
		  </td>
		 </tr>
	   <%end%>
	   </table>
   </td><td valign=top width=20% style="padding:2px">
	   <div style="margin-right:0px;border:1px #ccc solid;background:#efefef;white-space:normal;font-size:12px;font-weighti:bold;font-family:'ms shell dlg'">
       <b><%=sprintf('%0.2f',pt)%></b>
	   <hr size=1>
	   <%any_type = pt%>
	   <%project.activity_types.each do |a|%>
        <%=sprintf('%0.2f',(at = project.total_hours(a.id,@start_at,@end_at,@confirmed_time,@work_time)))%>:<%=a.name%><br>
		<%any_type = any_type - at%>
		<%end%>
		<%=sprintf('%0.2f',any_type)%>:<%='ANY type'.t%>
		</div>
   </td>
 </tr>
 <%
   p_count += 1
   p_total += pt
 %>
 <%end%>
 <tr class=th>
  <td><%='Projects'.t%>:<%=p_count%></td>
  <td colspan=2><%='Total hours'.t%>:<%=sprintf("%0.2f",p_total)%></td>
 </table>
